﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Hotel.QLPhong
{
    public partial class ReportHoaDonThanhToan : Form
    {
        private string tenkh, ngaysinhkh, gioitinhkh, cmdnkh, sodtkh, quoctichkh, diachikh;
        private string tongtienphong, tongtiendv, songaydao;
        private string daythue, maphong;
        public ReportHoaDonThanhToan(string tkh, string ns, string gt, string cmnd, string sdt, string qt, string dc, string dt, string mp, string ttp, string ttdv, string songayo)
        {
            this.tenkh = tkh;
            this.ngaysinhkh = ns;
            this.gioitinhkh = gt;
            this.cmdnkh = cmnd;
            this.sodtkh = sdt;
            this.quoctichkh = qt;
            this.diachikh = dc;
            this.daythue = dt;
            this.maphong = mp;
            this.tongtienphong = ttp;
            this.tongtiendv = ttdv;
            this.songaydao = songayo;
            InitializeComponent();
        }

        private SqlConnection con;
        private SqlDataAdapter da;

        private void connect()
        {
            string cn = "Data Source=.;Initial Catalog=Hotel;Integrated Security=True";

            try
            {
                con = new SqlConnection(cn);
                con.Open();
            }
            catch (Exception)
            {
                MessageBox.Show("Khong the ket noi co so du lieu", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void ReportHoaDonThanhToan_Load(object sender, EventArgs e)
        {
            connect();
            da = new SqlDataAdapter("SELECT KhoDichVu.TenHang, DichVuPhong.SoLuong, DichVuPhong.NgaySuDung, DichVuPhong.TongTien FROM DichVuPhong,KhoDichVu WHERE DichVuPhong.MaPhong LIKE '"+
                maphong+"' AND DichVuPhong.NgaySuDung >= '"+daythue+"' AND DichVuPhong.MaHang = KhoDichVu.MaHang", con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            rptHoaDonPhong rpt = new rptHoaDonPhong();
            // thong tin khach hang
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["tenkh"]).Text = tenkh;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["ngaysinh"]).Text = ngaysinhkh;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["gioitinh"]).Text = gioitinhkh;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["cmnd"]).Text = cmdnkh;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["dienthoai"]).Text = sodtkh;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["quoctich"]).Text = quoctichkh;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["ngaythue"]).Text = daythue;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["diachi"]).Text = diachikh;
            // thong tin phong thue
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["sophong"]).Text = maphong;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["songaydao"]).Text = songaydao;
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["tongtienphong"]).Text = tongtienphong + "  VND";
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["tongtiendv"]).Text = tongtiendv + "  VND";
            // tong tien phai tra.
            long tongtien = Convert.ToInt32(tongtienphong) + Convert.ToInt32(tongtiendv);
            ((CrystalDecisions.CrystalReports.Engine.TextObject)rpt.ReportDefinition.ReportObjects["tongtien"]).Text = tongtien + "  VND";
            rpt.SetDataSource(dt);
            rpt.Refresh();
            // thong tin dich vu da dung
            this.crystalReportViewer1.ReportSource = rpt;
        }
    }
}
